package com.icons.draw.view;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ZoomControls;

import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import data.*;

public class LocationViewers extends LinearLayout {

	private MapLocationOverlay overlay;
	
    //  Known lat/long coordinates that we'll be using.
   // private List<MapLocation> mapLocations;
    
    public static MapView mapView;
    public ParkingDB parking_db;
    
   // public Vector<ParkingSpotsList> parkingVector=null;
	
    
	public LocationViewers(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public LocationViewers(Context context) {
		super(context);
		init();
	}
	
	public void init() {		
		setOrientation(VERTICAL);
		setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.FILL_PARENT));
		String api = getResources().getString(com.blahti.example.drag2.R.string.map_api_key);
		mapView = new MapView(getContext(),api);
		mapView.setEnabled(true);
		mapView.setClickable(true);
		addView(mapView);
		parking_db=ParkingDB.getInstance();
		overlay = new MapLocationOverlay(this,mapView);
    	//mapView.getController().setZoom(5);
    	//mapView.getController().setCenter(getMapLocations().get(0).getPoint());
		if((parking_db.curLoc!=null)&&(parking_db.gps))
		mapView.getController().setCenter(parking_db.curLoc.getPoint());
		else
			mapView.getController().setCenter(parking_db.noGpsLoc.getPoint());

			
		mapView.getOverlays().add(overlay);


	}
/*	
	
	public List<MapLocation> getMapLocations() {
		if (mapLocations == null) {
			mapLocations = new ArrayList<MapLocation>();
			mapLocations.add(new MapLocation("PRESS AGAIN TO EDIT THE MAP",32.068188492013135,34.76519264280796));
			
	
		}
		return mapLocations;
	}
	/*
    public Vector<ParkingSpotsList> getParkingVectore ()
    {
    	
        if(parkingVector==null)
        {
        	Log.d("error LocationViewer","parking vector is null");

        }
        
        
    	return parkingVector;
    }
	*/
    public MapView getMapView() {
		return mapView;
	}
	

    
    


}
